package com.data.basic.chapter04;

import com.data.basic.chapter03.MyStack;

/** 链表实现栈
 * Created by wangbing on 2018/5/3.
 */
public class LinkedListStack<E> implements MyStack<E> {

    private LinkedListDemo02 list;

    public LinkedListStack() {
        this.list = new LinkedListDemo02();
    }


    public void push(E e) {
        list.addFirst(e);


    }

    public E pop() {
        return (E) list.removeFirst();
    }

    public E peek() {
        return (E) list.getFirst();
    }

    public int getSize() {
        return list.getSize();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder res= new StringBuilder();
        res.append("Stack:top");
        res.append(list);
        res.append("]");
        return res.toString();
    }

    public static void main(String[] args) {

        LinkedListStack<Integer>  stack = new LinkedListStack();
        for (int i=0;i<10;i++){
            stack.push(i);
            System.out.println(stack);
        }stack.pop();
        System.out.println(stack);

    }
}
